package manager;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;

import org.apache.commons.lang3.exception.ExceptionUtils;

import util.GlobalUtils;

public class GrowlManager {

    public static void addError(Exception e) {  
    	addToGrowl(FacesMessage.SEVERITY_ERROR, "ERROR:", ExceptionUtils.getRootCauseMessage(e));
    }  
    public static void addInfo(String header, String message) {
    	addToGrowl(FacesMessage.SEVERITY_INFO, header, message);
    }
    public static void addWarning(String header, String message) {
    	addToGrowl(FacesMessage.SEVERITY_WARN, header, message);
    }  

    private static void addToGrowl(Severity severity, String header, String message) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(
        		severity, GlobalUtils.getSizeLimitedText(header , 45), message));
    }
}
